/* engine.h --
 * Copyright 2009  cwxstat LLC., Elkins Park, Pennsylvania.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Authors:
 *     Mike Chirico <mchirico@gmail.com>
 *     
 */

#ifndef ENGINE_H
#define ENGINE_H

#include <pthread.h>
#include <signal.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>

#include <signal.h>
#include <syslog.h>

#include "thread_wrapper.h"


/* Global Data */
volatile int stop;
volatile int hup;
struct sigaction sa;

#define BUF_LEN 1025
char bbuf[BUF_LEN];

typedef struct CONNTBL CONNTBL;

pthread_mutex_t conn_mutex;
#define CTBLMAX 90

struct CONNTBL
{
	/* int conn; */
	SSL *conn;
	pthread_t t;
	int fd;
	int FLAG;
};

/* for asyc_write */
struct S_Buf
{
	SSL *conn;
	char *s;
	int i;
};

int conn_count;
CONNTBL conntbl[CTBLMAX];

int init_conn(void);
int remove_conn(int me);

/*  dev stuff */
int assign_conn(void *arg);

/* prototypes for wrapper functions */

#define	min(a,b)	((a) < (b) ? (a) : (b))
#define	max(a,b)	((a) > (b) ? (a) : (b))

#endif /* ENGINE_H */
